********************************************************************************
* Replication file for the paper: 											   *
* Defending the Status Quo or Seeking Change?								   *
* 	Electoral Outcomes, Affective Polarisation, and Support for Referendums	   *
* Date: 20 March 2025														   *
* Authors: Bjarn Eck & Emilien Paulis										   *
********************************************************************************

*** Set working directory yourself
*** packages: estout (ssc install estout, replace)

*** Open dataset 
	use "dataset", replace 


//==============================================================================	
// 1. DESCRIPTIVE ANALYSES
//==============================================================================

	
	* DV and government/opposition distribution
	tab1 ref_force ref_important if !missing(winlose)
	bys country: tab winlose 

	
	* T-tests by country
	bys country: ttest referendum, by(winlose) rev
	

//==============================================================================	
// 2. REGRESSION ANALYSES
//==============================================================================
		
	est clear
	global controls polint lr efficacy gender age education i.employment i.country
	tab swd
  
	* M0: Base model
	reg referendum winlose AP, vce(r)
	est store m1
	
	* M1: Add IVs
	reg referendum winlose AP $controls , vce(r)
	est store m2
	
	* M2: Add interactions
	reg referendum winlose##c.AP $controls , vce(r)
	est store m3
	
	esttab m1 m2 m3, ///
		scalars (N r2_a) label se nobase noomitted b(%9.3f) se(%9.3f) sfmt(%9.3f) wide ///
		star(* 0.05 ** 0.01 *** 0.001) obslast order(winlose AP *.winlose#c.AP) ///
		interaction(*) mti("M1" "M2" "M3") nonum drop(*.country)
		
	* Interaction plot 
	margins winlose, at(AP=(0(1)5))
	marginsplot, recast(line) recastci(rarea) ciopt(color(gs5%40)) ///
		xtitle("Affective Polarisation") ytitle("Referendum support (1-5)", ///
		size(small)) legend(position(6) row(1)) ///
		title("") ylab(3.4(.2)4) ///
		addplot(hist AP, percent ysc(r(3.4 4) ///
		axis(1))ylab(3.4(.2)4, axis(1)) yaxis(2) yscale(alt axis(2)) ///
		ytitle("Affective Polarisation (%)", axis(2) size(small)) ///
		fcolor(gs10%10) bcolor(gs5%50))
		// change legend and line colours manually 	
	
	

